<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('档案列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>课题：</label>
                                <select name="topId">
					                <option th:each="topic : ${topicList}" th:text="${topic.topicName}" th:value="${topic.topicId}" ></option>
					            </select>
                            </li>
                            <li>
                                <label>中心号：</label>
                                <input type="text" name="centerNo"/>
                            </li>
                            <li>
                                <label>筛选号：</label>
                                <input type="text" name="screeningNo"/>
                            </li>
                            <li>
                                <label>随机号：</label>
                                <input type="text" name="randomNo"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="kt:record:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="kt:record:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="kt:record:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('kt:record:edit')}]];
        var removeFlag = [[${@permission.hasPermi('kt:record:remove')}]];
        var topicList = [[${topicList}]]
        var prefix = ctx + "kt/record";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "档案",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'recordId',
                    title: '档案主键',
                    visible: false
                },
                {
                    field: 'topId',
                    title: '课题',
                    formatter: function (value, row, index) {
		        		return topicShow(value);
		        	}
                },
                {
                    field: 'demographyName',
                    title: '研究对象名称'
                },
                {
                    field: 'checkTime',
                    title: '检查时间'
                },
                {
                    field: 'centerNo',
                    title: '中心号'
                },
                {
                    field: 'screeningNo',
                    title: '筛选号'
                },
                {
                    field: 'randomNo',
                    title: '随机号'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.recordId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="study(\'' + row.recordId + '\')"><i class="fa fa-edit"></i>研究</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.recordId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function topicShow(topicId){
        	var actions = [];
        	$.each(topicList, function(index, topic) {
        		if(topic.topicId==topicId){
        			actions.push(topic.topicName);
        			return topic.topicName;
        		}
        	});
        	return actions.join();
        }
        
        function study(recordId){
        	$.modal.openTab("研究", prefix+"/study/"+recordId);
        }
    </script>
</body>
</html>